package ru.compft.common.data.acl;

import ru.compft.common.data.meta.acl.AclEntryTableMeta;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: VVasiliev
 * Date: 01.11.12
 * Time: 11:59
 * <p/>
 * Класс представляющий объект "Сущности в ACL"
 * <p/>
 * CREATE TABLE IF NOT EXISTS ACL_ENTRY (
 * ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 * ACL_OBJECT_IDENTITY INT(20) NOT NULL,
 * ACE_ORDER INT(11) NOT NULL,
 * SID INT(20) NOT NULL,
 * MASK INT(11) NOT NULL,
 * GRANTING VARCHAR(1) NOT NULL,
 * AUDIT_SUCCESS VARCHAR(1) NOT NULL,
 * AUDIT_FAILURE VARCHAR(1) NOT NULL,
 * CONSTRAINT UNIQUE_UK_4 UNIQUE(ACL_OBJECT_IDENTITY,ACE_ORDER),
 * CONSTRAINT FOREIGN_FK_4 FOREIGN KEY(ACL_OBJECT_IDENTITY) REFERENCES ACL_OBJECT_IDENTITY(ID),
 * CONSTRAINT FOREIGN_FK_5 FOREIGN KEY(SID) REFERENCES ACL_SID(ID)
 * )
 */
@Entity
@Table(name = AclEntryTableMeta.TABLE_NAME, uniqueConstraints = {
        @UniqueConstraint(columnNames = {AclEntryTableMeta.ACL_OBJECT_IDENTITY, AclEntryTableMeta.ACE_ORDER})})
public class AclEntry implements Serializable {
    private static final long serialVersionUID = 3947957325808171950L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = AclEntryTableMeta.ID, unique = true, nullable = false)
    private Long id;

    @Column(name = AclEntryTableMeta.ACL_OBJECT_IDENTITY, nullable = false, length = 20)
    private Long aclObjectIdentity;

    @Column(name = AclEntryTableMeta.ACE_ORDER, nullable = false, length = 11)
    private Long aceOrder;

    @Column(name = AclEntryTableMeta.SID, nullable = false, length = 20)
    private Long sid;

    @Column(name = AclEntryTableMeta.MASK, nullable = false, length = 11)
    private Long mask;

    @Column(name = AclEntryTableMeta.GRANTING, nullable = false, length = 1)
    private String granting;

    @Column(name = AclEntryTableMeta.AUDIT_SUCCESS, nullable = false, length = 1)
    private String auditSuccess;

    @Column(name = AclEntryTableMeta.AUDIT_FAILURE, nullable = false, length = 1)
    private String auditFailure;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = AclEntryTableMeta.ACL_OBJECT_IDENTITY, insertable = false, updatable = false)
    private AclObjectIdentity objectIdentity;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = AclEntryTableMeta.SID, insertable = false, updatable = false)
    private AclSid aclSid;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getAclObjectIdentity() {
        return aclObjectIdentity;
    }

    public void setAclObjectIdentity(Long aclObjectIdentity) {
        this.aclObjectIdentity = aclObjectIdentity;
    }

    public Long getAceOrder() {
        return aceOrder;
    }

    public void setAceOrder(Long aceOrder) {
        this.aceOrder = aceOrder;
    }

    public Long getSid() {
        return sid;
    }

    public void setSid(Long sid) {
        this.sid = sid;
    }

    public Long getMask() {
        return mask;
    }

    public void setMask(Long mask) {
        this.mask = mask;
    }

    public String getGranting() {
        return granting;
    }

    public void setGranting(String granting) {
        this.granting = granting;
    }

    public String getAuditSuccess() {
        return auditSuccess;
    }

    public void setAuditSuccess(String auditSuccess) {
        this.auditSuccess = auditSuccess;
    }

    public String getAuditFailure() {
        return auditFailure;
    }

    public void setAuditFailure(String auditFailure) {
        this.auditFailure = auditFailure;
    }

    public AclObjectIdentity getObjectIdentity() {
        return objectIdentity;
    }

    public void setObjectIdentity(AclObjectIdentity objectIdentity) {
        this.objectIdentity = objectIdentity;
    }

    public AclSid getAclSid() {
        return aclSid;
    }

    public void setAclSid(AclSid aclSid) {
        this.aclSid = aclSid;
    }
}
